package com.android.aishangauction.activity.mine;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.aishangauction.R;
import com.android.aishangauction.app.BaseActivity;
import com.android.aishangauction.utils.ConstantsUrl;
import com.just.library.AgentWeb;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/10/26.
 */

public class NewGuideActivity extends BaseActivity {
    @BindView(R.id.mLinearLayout)
    FrameLayout mLinearLayout;
    @BindView(R.id.webView)
    WebView webView1;
    @BindView(R.id.progress)
    RelativeLayout progress;
    @BindView(R.id.main_top_title)
    TextView main_top_title;
    private FragmentActivity mcontext;
    private View view;

    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    private String detail_content="";
    private String webUrl;
    AgentWeb agentweb;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_newguide);
        ButterKnife.bind(this);
        webUrl = getIntent().getStringExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_WEB_URL);
        String title = getIntent().getStringExtra("title");
        main_top_title.setText(title);
        agentweb = AgentWeb.with(this)//传入Activity or Fragment
                .setAgentWebParent(mLinearLayout, new LinearLayout.LayoutParams(-1, -1))//传入AgentWeb 的父控件 ，如果父控件为 RelativeLayout ， 那么第二参数需要传入 RelativeLayout.LayoutParams ,第一个参数和第二个参数应该对应。
                .useDefaultIndicator()// 使用默认进度条
                .defaultProgressBarColor() // 使用默认进度条颜色
                .createAgentWeb()//
                .ready()
                .go(webUrl);
       // initUI();
    }

    private void initUI() {
//        WebSettings settings = webView1.getSettings();
//        settings.setJavaScriptEnabled(true);
//        webUrl = getIntent().getStringExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_OBJEXT_SORT_WEB_URL);
//        if (webUrl.equals("")) {
//            if (detail_content != null && !detail_content.equals("")) {
//                progress.setVisibility(View.GONE);
//                nodata.setVisibility(View.GONE);
//                webView1.setWebViewClient(new MyWebViewClient());
//                webView1.setWebChromeClient(new WebChromeClient() {
//                    @Override
//                    public void onProgressChanged(WebView view, int newProgress) {
//                        super.onProgressChanged(view, newProgress);
//                        if (newProgress == 100) {
//                            progress.setVisibility(View.GONE);
//                        }
//                    }
//                });
//                //宽度适应屏幕
//                String js = "<style>\n" +
//                        "img{\n" +
//                        " max-width:100%;\n" +
//                        "height:auto\n" +
//                        "}\n" +
//                        "</style>" + detail_content;
//
//                webView1.loadDataWithBaseURL(null, js, "text/html", "utf-8", null);
//            } else {
//                progress.setVisibility(View.GONE);
//                nodata.setVisibility(View.VISIBLE);
//            }
//        } else {
//            progress.setVisibility(View.GONE);
//            nodata.setVisibility(View.GONE);
//            MyLog.e("weburl1",webUrl);
//            webView1.setWebViewClient(new MyWebViewClient());
//            webView1.setWebChromeClient(new WebChromeClient() {
//                @Override
//                public void onProgressChanged(WebView view, int newProgress) {
//                    super.onProgressChanged(view, newProgress);
//                    if (newProgress == 100) {
//                        progress.setVisibility(View.GONE);
//                    }
//                }
//            });
//            if (!"".equals(webUrl)) {
//                webView1.loadUrl("http://ptmore1.lnest.cc/chat?good_id=1");
//            }
//        }
    }

    class MyWebViewClient extends WebViewClient {
        //拦截网址
    }
    @OnClick({R.id.main_top_back})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.main_top_back:
                finish();
                break;
        }
        }
    @Override
    protected void onDestroy() {
        if (webView1 != null) {
//            webView1.loadDataWithBaseURL(null, "", "text/html", "utf-8", null);
//            webView1.clearHistory();
//
//            ((ViewGroup)webView1.getParent()).removeView(webView1);
            webView1.destroy();
            webView1 = null;
        }
        super.onDestroy();
    }

}
